package org.neurone.userspace.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.neurone.domain.UserInfo;
import org.neurone.domain.UserDetailInfo;
import org.neurone.domain.persistence.UserDetailInfoPersistence;
import org.neurone.domain.persistence.UserInfoPersistence;

public class UserDetailDaoMock implements UserDetailDao {
	private HashMap<Long, UserDetailInfo> userDetailList;
	private UserInfoDao userInfoDao;
	
	public UserInfoDao getUserInfoDao() {
		return userInfoDao;
	}

	public UserDetailDaoMock setUserInfoDao(UserInfoDao userInfoDao) {
		this.userInfoDao = userInfoDao;
		return this;
	}

	@Override
	public void addDetail(Long userID, UserDetailInfo userDetail) {
		UserInfo u = userInfoDao.find(userID);
		((UserDetailInfoPersistence)userDetail).setBelongUser((UserInfoPersistence)u);
		userDetailList.put(userDetail.getUserDetailInfoID(), userDetail);
	}

	@Override
	public List<UserDetailInfo> getUserDetail(Long userID) {
		List<UserDetailInfo> udList = new ArrayList<UserDetailInfo>();
		
		for (UserDetailInfo userDetailInfo : userDetailList.values()) {
			if(userDetailInfo.getBelongUser().getUserID().equals(userID))
			{
				udList.add(userDetailInfo);
			}
		}
		
		return udList;
	}

	@Override
	public void update(UserDetailInfo userDetail) {
		userDetailList.put(userDetail.getUserDetailInfoID(), userDetail);
	}

	@Override
	public void deleteDetail(Long userDetailID) {
		userDetailList.remove(userDetailID);
	}
	
	public UserDetailDaoMock()
	{
		userDetailList = new HashMap<Long, UserDetailInfo>();
	}

	@Override
	public UserDetailInfo find(Long userDetailID) {
		UserDetailInfoPersistence udip = new UserDetailInfoPersistence();
		udip.setUserDetailInfoID(userDetailID);
		return udip;
	}

}
